﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BBCP.UI.Tasks;
using BBCP.Model;

namespace BBCP.UI.Customers
{
    public class AddCustomer : ITask
    {
        public bool Run()
        {
            try
            {
                using (var context = new NorthwindEntities())
                {
                    context.AddToCustomers(CreateCutomer());
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Błąd dodawnia klienta.\n Szczegóły błędu: {0}", e.Message);
            }
            return true;
        }

        private BBCP.Model.Customers CreateCutomer()
        {
            var customer = new Model.Customers();
            
            Console.Write("ID klienta (5 liter): ");
            customer.CustomerID = Console.ReadLine();

            Console.Write("Nazwa firmy: ");
            customer.CompanyName = Console.ReadLine();

            Console.Write("Imie / Nazwisko ");
            customer.ContactName = Console.ReadLine();

            Console.Write("Tytuł: ");
            customer.ContactTitle = Console.ReadLine();

            Console.Write("Adres: ");
            customer.Address = Console.ReadLine();

            Console.Write("Miasto: ");
            customer.City = Console.ReadLine();

            Console.Write("Region: ");
            customer.Region = Console.ReadLine();

            Console.Write("Kod pocztowy: ");
            customer.PostalCode = Console.ReadLine();

            Console.Write("Kraj: ");
            customer.Country = Console.ReadLine();

            Console.Write("Telefon: ");
            customer.Phone = Console.ReadLine();

            Console.Write("Fax: ");
            customer.Fax = Console.ReadLine();

            return customer;
        }
    }
}
